package com.htwy.ext;

import com.htwy.kits.CommonKit;
import com.jfinal.kit.StrKit;
import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;

public class SqlSetDirective extends ExtDirective {
    @Override
    public void exec(Env env, Scope scope, Writer writer) {
        String content = getContent(env, scope);
        if(StrKit.notBlank(content)){
            content = CommonKit.trimSpace(content);
            if(content.length() > 0) {
                write(writer, " SET ");
                int length = content.length();
                if (content.charAt(length - 1) == ',') {
                    write(writer, content.substring(0, length - 1));
                } else {
                    write(writer, content);
                }
                write(writer, " ");
            }
        }
    }

    @Override
    public boolean hasEnd() {
        return true;
    }
}
